package base;

import java.util.Random;

public class extract {
    public static void main(String[] args) {
        //1.定义一个数组为 奖池
        int[] arr = {1,2,3,4,5};
        //抽到的 奖项 放入新数组里
        int[] jackpot = new int[arr.length];
        //抽奖环节
        Random r = new Random();
        for (int i=0;i<arr.length;){
            int index = r.nextInt(arr.length);
            int prize = arr[index];

            if ( contains(jackpot,prize)){
                jackpot[i] = prize;
                i++;  //移动索引
            }
        }
        for (int i = 0; i < jackpot.length; i++) {
            System.out.print(jackpot[i]+",");
        }
    }


   //判断奖项是否已在奖池
    public static boolean contains(int[] jackpot,int prize){
        for (int i = 0; i < jackpot.length; i++) {
            if (jackpot[i] == prize){
                return false;
            }
        }
        return true;
    }
}
